package com.hnucm.cooklife.model;

import com.hnucm.cooklife.base.BaseModel;
import com.hnucm.cooklife.bean.db.Dish;
import com.hnucm.cooklife.bean.home.DishData;
import com.hnucm.cooklife.contract.dishresult.Contract;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;

public class DishResultModel extends BaseModel implements Contract.IDishResultModel {
    @Override
    public Observable<List<Dish>> loadDishResult(int currentPage, Map<String,String> dishName) {
        return mApiServer.loadDishResult(currentPage,dishName)
                .map(dishData -> {
                    List<Dish> dishList = new ArrayList<>();
                    dishData.getData().getRecords().stream().forEach(dataDTO -> {
                        Dish dishDB = new Dish();
                        dishDB.id = dataDTO.getDishId();
                        dishDB.dishname = dataDTO.getDishname();
                        dishDB.dishdesc = dataDTO.getDishdesc();
                        dishDB.dishdone = dataDTO.getDishdone();
                        dishDB.dishscore = dataDTO.getDishscore();
                        dishDB.userid = dataDTO.getUserid();
                        dishDB.icon = dataDTO.getIcon();
                        dishDB.dishpic = dataDTO.getDishpic();
                        dishDB.bg = dataDTO.getBg();
                        dishDB.username = dataDTO.getUsername();
                        System.out.println(dataDTO);
                        dishList.add(dishDB);
                    });
                    System.out.println("dish搜索结果");
                    System.out.println(dishList);
                    return dishList;
                });
    }

    @Override
    public Observable<List<Dish>> refreshDishResult(int currentPage,Map<String,String> dishName) {
        return loadDishResult(currentPage,dishName);
    }
}
